package com.cw.service;

import com.cw.beans.User;
import com.cw.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Map;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    UserMapper userMapper;


    @Override
    public ArrayList <User> getUserList() {
        return userMapper.getUserList();
    }
     public User getUserById(int id ){
         return userMapper.getUserById(id);
     }
     public void addUser(User user){
         userMapper.addUser(user);

     }

     public Map updateUser(User user,Map map){
         User userByUserName = userMapper.getUserByUserName(user.getUsername());
         if(userByUserName != null && user.getId() != userByUserName.getId()){
             map.put("msg","用户名已存在");
         }else {
             userMapper.updateUser(user);
             map.put("msg","修改成功");
         }

         return map;

     }
}
